﻿using System;
using Microsoft.Xna.Framework;
using CellarDoor.Gui.Elements;

namespace CellarDoor.Gui.Animation
{
    public class AnimateSize : AnimateComponent
    {
        /// <summary>
        /// The start sizie
        /// </summary>
        public Vector2 StartValue { get; set; }

        /// <summary>
        /// The end size
        /// </summary>
        public Vector2 EndValue { get; set; }

        public bool SetWidth { get; set; }
        public bool SetHeight { get; set; }

        public AnimateSize(UiElement element)
            : base(element)
        {
            SetWidth = true;
            SetHeight = true;
        }

        public AnimateSize(UiElement element, Vector2 start, Vector2 end, float durationInMs)
            : this(element)
        {
            SetWidth = true;
            SetHeight = true;
            StartValue = start;
            EndValue = end;
            Duration = durationInMs;
        }

        protected override void Animate()
        {
            Vector2 size = StartValue + (EndValue - StartValue) * EasedProgress;
            if (!SetWidth)
                size.X = Target.Size.X;
            if (!SetHeight)
                size.Y = Target.Size.Y;
            Target.Size = size;
        }
    }
}
